package com.shunya.diskorganizer;

import java.net.URI;

public enum FileDownloader {
    HTTP("http") {
        @Override
        void download(URI uri) {
            System.out.println("http download");
            //To change body of implemented methods use File | Settings | File Templates.
        }
    },
    FTP("ftp") {
        @Override
        void download(URI uri) {
            System.out.println("ftp download");
            //To change body of implemented methods use File | Settings | File Templates.
        }
    },
    SAMBA("smb") {
        @Override
        void download(URI uri) {
            System.out.println("smb download");
            //To change body of implemented methods use File | Settings | File Templates.
        }
    },
    FILE_SYSTEM("file") {
        @Override
        void download(URI uri) {
            System.out.println("file download");
            //To change body of implemented methods use File | Settings | File Templates.
        }
    };

    public String getProtocol() {
        return protocol;
    }

    private String protocol;

    FileDownloader(String protocol) {
        this.protocol = protocol;
    }

    abstract void download(URI uri);

    public static void downloadFile(URI uri) {
        String urlProtocol = uri.getScheme().toLowerCase();
        for (FileDownloader downloader : FileDownloader.values()) {
            if(downloader.getProtocol().equalsIgnoreCase(urlProtocol)){
                downloader.download(uri);
                return;
            }
        }
    }
}